#define _CRT_SECURE_NO_WARNINGS 
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
struct cow {
	int p, a;
}b[5001];
void QuickSort(struct cow* q, int low, int high) {
	if (low < high) {
		int i = low;
		int j = high;
		int key = q[low].p;
		int qwe = q[low].a;
		while (i < j) {
			while (i < j && q[j].p >= key)
				j--;
			if (i < j)
				q[i++] = q[j];
			while (i < j && q[i].p < key)
				i++;
			if (i < j)
				q[j--] = q[i];

		}
		q[i].p = key;
		q[i].a = qwe;
		QuickSort(q, low, i - 1);
		QuickSort(q, i + 1, high);

	}

}
int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++)
	{
		scanf("%d%d", &b[i].p, &b[i].a);
	}
	QuickSort(b, 0, m - 1);
	int sum = 0;
	int money = 0;
	for (int i = 0; i < m; i++)
	{
		if (sum + b[i].a <= n)
		{
			sum += b[i].a;
			money += b[i].a*b[i].p;
		}
		else
		{
			for (int j = 1;; j++)
			{
				sum += 1;
				if (sum == n)
				{
					money += j * b[i].p;
					break;
				}
			}
		}
		if (sum >= n)
			break;
	}
	printf("%d", money);
	return 0;
}